package com.forezp.servicemiya;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@SpringBootApplication
public class ServiceMiyaApplication {
    private Logger logger = LoggerFactory.getLogger(ServiceMiyaApplication.class);

    public static void main(String[] args) {
        SpringApplication.run(ServiceMiyaApplication.class, args);
    }

    @Bean
    @LoadBalanced
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    @RequestMapping("/hi")
    public String callHome() {
        logger.info("hi is being called");
        return "hi i'm service-miya";
    }

    @RequestMapping("/miya")
    public String info() {

        logger.info("info is being called");
        return restTemplate().getForObject("http://localhost:8988/info", String.class);
    }
}

